﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace helicopterFight
{
    class Sky : GameObject
    {
        GraphicsDevice device;
        public GameObject target;

        public void init(Game1 game)
        {
            device = game.GraphicsDevice;
            model = game.Content.Load<Model>("models/sky/sky");
            scale = 10;
        }

        public override void update()
        {
            position = target.position;
        }

        public override void draw()
        { 
            device.RenderState.DepthBufferWriteEnable = false;
            Matrix[] modelTransforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(modelTransforms);

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect currentEffect in mesh.Effects) /* BesicEffect - Effect*/
                {
                    Matrix worldMatrix = 
                        modelTransforms[mesh.ParentBone.Index] *
                        Matrix.CreateScale(scale) *
                        Matrix.CreateTranslation(position);


                    currentEffect.World =
                        worldMatrix;
                    currentEffect.Projection = cam.CameraProjectionMatrix;
                    currentEffect.View = cam.CameraViewMatrix;
                 }
                 mesh.Draw();
             }
             device.RenderState.DepthBufferWriteEnable = true;
         }
    }
}
